<?php
$IN_defaultpl="default";
include (dirname(__FILE__)."/index.inc.php");//全局变量

$web_userId=trim(isset($_SESSION['web_user_uid'])?$fun->authcode($_SESSION['web_user_uid'], 'DECODE', $pwdconstant,$expiry =0):"");
//$web_userId=trim(isset($_COOKIE['web_user_uid'])?$fun->authcode($_COOKIE['web_user_uid'], 'DECODE', $pwdconstant,$expiry =0):"");

if($web_userId){
	$userInfo=$db->get_one("SELECT u.`uid`, u.`status`, u.`uname`, u.`realname`, u.`ncname`, u.`sex`, u.`mobile`, u.`tel`, u.`email`, u.`qq`, u.`addtime`, u.`lastlogintime`, u.`logintime`, u.`is_valid`, u.`login_num`, u.`modify_ip`,t.`id` FROM `{$tbprefix}user` AS u LEFT JOIN `{$tbprefix}user_token` AS t ON t.uid=u.uid WHERE u.`uid`='{$web_userId}' AND 1");
}else{
	$userInfo=array("uid"=>0,"uname"=>"Unknown");
}
$smarty->assign("userInfo",$userInfo);

//QQ授权 token表id
$web_qq_id=trim(isset($_SESSION['web_qq_token_id'])?$fun->authcode($_SESSION['web_qq_token_id'], 'DECODE', $pwdconstant,$expiry =0):"");
$smarty->assign("web_qq_id",$web_qq_id);
//新浪授权 token表id
$web_sina_id=trim(isset($_SESSION['web_sina_token_id'])?$fun->authcode($_SESSION['web_sina_token_id'], 'DECODE', $pwdconstant,$expiry =0):"");
$smarty->assign("web_sina_id",$web_sina_id);

//在线客服
$web_online=$db->get_all("SELECT `id`, `online_name`, `online_account`, `addtime`, `changetime`, `type_form` FROM `{$tbprefix}online` WHERE `is_show`='1' AND `is_valid`='1' AND 1 ORDER BY orderid DESC,addtime DESC");
$smarty->assign("web_online",$web_online);


switch ($mod){
	case "index"://首页
		//首页广告位
		$Advertising=$db->get_all("SELECT `id`,`img_name`,`img_url`,`img_src` FROM `{$tbprefix}ad_img` WHERE `is_show`='1' AND type='2' AND `is_valid`='1' AND 1 ORDER BY `orderid` DESC LIMIT 0,15");
		$smarty->assign("Advertising",$Advertising);
		
		$smarty->display("index".$list_url['suffix_tpl']);
		break;
		
	case "login"://登录
		if(!empty($userInfo['uid'])){
			//只允许未登录的会员登录
			echo "<script  type='text/javascript' language='javascript'>window.location.href='".$list_url['index']."';</script>";
			exit();
		}
		//页面操作
		switch ($act){
			case "login_do"://登录操作
				include_once (dirname(__FILE__)."/contral/login_do.php");
				break;
		}
		$smarty->display("login".$list_url['suffix_tpl']);
		break;		
		
	case "register"://注册
		//页面操作
		if(!empty($userInfo['uid'])){
			//只允许未登录的会员
			echo "<script  type='text/javascript' language='javascript'>window.location.href='".$list_url['index']."';</script>";
			exit();
		}
		switch ($act){
			case "register_do"://登录操作
				include_once (dirname(__FILE__)."/contral/register_do.php");
				break;
		}
		
		$smarty->display("register".$list_url['suffix_tpl']);
		break;
		
	case "bindqzone"://首次注册绑定QQ
		//1 表示不使用接口session 同时标识是qq
		$new_session_bind_set=1;
		//token表id
		$user_token_id=$web_qq_id;
		//返回链接
		$return_page_url=$list_url['bindqzone'];
		
		if(empty($web_qq_id)){
			//只允许授权的会员 否则跳转到授权页面
			echo "<script  type='text/javascript' language='javascript'>window.location.href='./tools/oauth/index.php';</script>";
			exit();
		}
		//页面操作
		switch ($act){
			case "register_bind_do"://注册绑定操作
				include_once (dirname(__FILE__)."/contral/register_bind_do.php");
				break;
			case "login_bind_do"://登录绑定操作
				include_once (dirname(__FILE__)."/contral/login_bind_do.php");
				break;
			case "bind_qq"://qq首次绑定
				$qq_first_bind=1;
				include_once (dirname(__FILE__)."/contral/get_qq_message.php");
				break;
		}
		$smarty->display("binding".$list_url['suffix_tpl']);
		break;
	
	case "bindsina"://首次注册绑定新浪
		//1 表示不使用接口session 同时标识是新浪
		$new_session_bind_set=2;
		//token表id
		$user_token_id=$web_sina_id;
		//返回链接
		$return_page_url=$list_url['bindsina'];
		
		if(empty($web_sina_id)){
		 //只允许授权的会员 否则跳转到授权页面
			echo "<script  type='text/javascript' language='javascript'>window.location.href='./tools/oauth2/index.php';</script>";
			exit();
		}
		//页面操作
		switch ($act){
			case "register_bind_do"://注册绑定操作
				include_once (dirname(__FILE__)."/contral/register_bind_do.php");
				break;
			case "login_bind_do"://登录绑定操作
				include_once (dirname(__FILE__)."/contral/login_bind_do.php");
				break;
		}
		$smarty->display("binding".$list_url['suffix_tpl']);
		break;
		
	case "foget_password"://忘记密码
		
		if(!empty($userInfo['uid'])){
			//只允许未登录的会员
			echo "<script  type='text/javascript' language='javascript'>window.location.href='".$list_url['index']."';</script>";
			exit();
		}
		//通过ajax操作
		$smarty->display("foget_password".$list_url['suffix_tpl']);
		break;
		
	case "change_password"://修改密码
		//页面操作
		if(empty($userInfo['uid'])){
			//只允许登录的会员修改密码
			echo "<script  type='text/javascript' language='javascript'>window.location.href='".$list_url['index']."';</script>";
			exit();
		}
		switch ($act){
			case "change_password_do"://登录操作
				include_once (dirname(__FILE__)."/contral/change_password_do.php");
				break;
		}
		$smarty->display("change_password".$list_url['suffix_tpl']);
		break;
		
	case "exit"://退出登录
		//本网退出
		unset($_SESSION['web_user_uid']);		//清除登录的用户id
		unset($_SESSION['token']);				//sina保存的session
		unset($_SESSION['web_sina_token_id']);	//sina同步登录保存的绑定token表id
		unset($_SESSION['QC_userData']);		//QQ保存的session
		unset($_SESSION['web_qq_token_id']);	//QQ同步登录保存的绑定token表id
		
		//同步退出
		/* SHOPNC loginout */
		$shopncloginout = SHOPNC_DOMAIN."index.php?act=login&op=logout";
		echo '<iframe height=0 width=0 style="display:none;" src="'.$shopncloginout.'"></iframe>';
		/* SHOPNC loginout */
		
		
		/* discuz loginout */
		$discuzloginout = DISCUZ_DOMAIN."member.php?mod=logging&action=logout";
		echo '<iframe height=0 width=0 style="display:none;" src="'.$discuzloginout.'"></iframe>';
		/* discuz loginout */
		//if($url_from==2){$url_from = 1;}
		$backurl = $fun->back_to_which_from($url_from);
		
		
		$fun->msg("您已成功退出登录",$backurl,2,$title="退出提示",$back_color="f78a12");
		break;
		
	case "help"://帮助
		
		//跳转到论坛网络
		echo "<script  type='text/javascript' language='javascript'>window.location.href='".DISCUZ_DOMAIN."forum.php';</script>";
		exit();
	
		break;
		
	default:
		$fun->msg("无效的链接,正在返回中...","",2,$title="错误页面提示",$back_color="f78a12");
		break;
}
?>